﻿using FlyHorse.LIMS.Model;
using FlyHorse.LIMS.WinApp.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace FlyHorse.LIMS.WinApp.Utils
{
    /// <summary>
    /// 用来把查询结果转换格式后绑定到gridcontrol
    /// </summary>
    public static class TransformReport
    {
        /// <summary>
        /// 转换原材料报告的查询结果
        /// </summary>
        /// <param name="reportList"></param>
        public static List<ReportRawModel> TransformRawReport(List<ReportRaw> reportList)
        {
            List<ReportRawModel> ListForGrid = new List<ReportRawModel>();
            foreach (var report in reportList)
            {
                ReportRawModel model = new ReportRawModel();
                model.ReportRawID = report.ReportRawID;
                model.SampleNO = report.SampleNO;
                model.GoodsID = report.GoodsID;
                model.BatchNumber = report.BatchNumber;
                model.ProductionUnit = report.ProductionUnit;
                model.SampleSendPerson = report.SampleSendPerson;
                model.SendDate = report.SendDate;
                model.Conclusion = report.Conclusion;
                model.TotalVehicle = report.TotalVehicle;
                model.PlateNumber = report.PlateNumber;
                model.LoginUserID = report.LoginUserID;
                model.AddDateTime = report.AddDateTime;
                model.ReportRawResults = report.ReportRawResults.ToList();

                foreach (var result in report.ReportRawResults)
                {
                    string id = result.TestItemID;
                    switch (id)
                    {
                        case "48":
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.BiZhong = Convert.ToDecimal(result.TestValue);
                                model.BiZhongJudge = result.Conclusion;
                            }
                            break;
                        case "49":
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.ShuiFen = Convert.ToDecimal(result.TestValue);
                                model.ShuiFenJudge = result.Conclusion;
                            }
                            break;
                        case "54":
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.BMCI = Convert.ToDecimal(result.TestValue);
                                model.BMCIJudge = result.Conclusion;
                            }
                            break;
                        case "61":
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.EnShiNianDu = Convert.ToDecimal(result.TestValue);
                                model.EnShiNianDuJudge = result.Conclusion;
                            }
                            break;
                        case "50":
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.YuanLiaoYouHuiFen = Convert.ToDecimal(result.TestValue);
                                model.YuanLiaoYouHuiFenJudge = result.Conclusion;
                            }
                            break;
                        case "51":
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Na = Convert.ToDecimal(result.TestValue);
                                model.NaJudge = result.Conclusion;
                            }
                            break;
                        case "52":
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.K = Convert.ToDecimal(result.TestValue);
                                model.KJudge = result.Conclusion;
                            }
                            break;
                        case "53":
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.LiQingZhi = Convert.ToDecimal(result.TestValue);
                                model.LiQingZhiJudge = result.Conclusion;
                            }
                            break;
                        case "55":
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.LiuFen = Convert.ToDecimal(result.TestValue);
                                model.LiuFenJudge = result.Conclusion;
                            }
                            break;

                    }

                    #region 废弃代码
                    //if (result.TestItemID == "48")  //比重
                    //{
                    //    model.BiZhong = Convert.ToDecimal(result.TestValue);
                    //    model.BiZhongJudge = result.Conclusion;
                    //}
                    //else if (result.TestItemID == "49")   //水分
                    //{
                    //    model.ShuiFen = Convert.ToDecimal(result.TestValue);
                    //    model.ShuiFenJudge = result.Conclusion;
                    //}
                    //else if (result.TestItemID == "54")   //BMCI
                    //{
                    //    model.BMCI = Convert.ToDecimal(result.TestValue);
                    //    model.BMCIJudge = result.Conclusion;
                    //}

                    //else if (result.TestItemID == "61")   //恩氏黏度
                    //{
                    //    model.EnShiNianDu = Convert.ToDecimal(result.TestValue);
                    //    model.EnShiNianDuJudge = result.Conclusion;
                    //}

                    //else if (result.TestItemID == "50")   //原料油灰分
                    //{
                    //    model.YuanLiaoYouHuiFen = Convert.ToDecimal(result.TestValue);
                    //    model.YuanLiaoYouHuiFenJudge = result.Conclusion;
                    //}

                    //else if (result.TestItemID == "51")   //NA﹢
                    //{
                    //    model.Na = Convert.ToDecimal(result.TestValue);
                    //    model.NaJudge = result.Conclusion;
                    //}

                    //else if (result.TestItemID == "52")   //K+
                    //{
                    //    model.K = Convert.ToDecimal(result.TestValue);
                    //    model.KJudge = result.Conclusion;
                    //}

                    //else if (result.TestItemID == "53")   //沥青质
                    //{
                    //    model.LiQingZhi = Convert.ToDecimal(result.TestValue);
                    //    model.LiQingZhiJudge = result.Conclusion;
                    //}

                    //else if (result.TestItemID == "55")   //硫份
                    //{
                    //    model.LiuFen = Convert.ToDecimal(result.TestValue);
                    //    model.LiuFenJudge = result.Conclusion;
                    //}
                    #endregion

                }
                ListForGrid.Add(model);
            }
            return ListForGrid;
        }


        /// <summary>
        /// 转换过程报告的查询结果用来绑定到grid
        /// </summary>
        /// <param name="reportList"></param>
        /// <returns></returns>
        public static List<ReportSemiModel> TransformSemiReport(List<ReportSemi> reportList)
        {
            List<ReportSemiModel> listForGrid = new List<ReportSemiModel>();
            foreach (var report in reportList)
            {
                ReportSemiModel model = new ReportSemiModel();
                model.ReportSemiID = report.ReportSemiID;

                model.GoodsID = report.GoodsID;
                model.GoodsName = report.Good.GoodsName;

                model.SamplingPlaceID = report.SamplingPlaceID;
                model.SamplingPlaceName = report.SamplingPlace.SamplingPlaceName;

                model.ProductionLineID = report.ProductionLineID;
                model.ProductionGroupID = report.ProductionGroupID;
                model.SendDate = report.SendDate;
                model.Remark = report.Remark;
                model.LoginUserID = report.LoginUserID;
                model.AddDateTime = report.AddDateTime;
                model.ReportSemiResults = report.ReportSemiResults.ToList();

                foreach (var result in report.ReportSemiResults)
                {
                    string id = result.TestItemID;
                    switch (id)
                    {
                        case "1": //IA
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.IA = Convert.ToDecimal(result.TestValue);
                                model.IAJudge = result.Conclusion;
                            }
                            break;
                        case "7":   //DBP
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.DBP = Convert.ToDecimal(result.TestValue);
                                model.DBPJudge = result.Conclusion;
                            }
                            break;
                        case "46":  //IPH(AVG)
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.IPH_AVG = Convert.ToDecimal(result.TestValue);
                                model.IPH_AVGJudge = result.Conclusion;
                            }
                            break;
                        case "8":  //IPH(IPH_High)
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.IPH_High = Convert.ToDecimal(result.TestValue);
                                model.IPH_HighJudge = result.Conclusion;
                            }
                            break;
                        case "30":  //IPH_Low
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.IPH_Low = Convert.ToDecimal(result.TestValue);
                                model.IPH_LowJudge = result.Conclusion;
                            }
                            break;
                        case "9":  //Fines
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Fines = Convert.ToDecimal(result.TestValue);
                                model.FinesJudge = result.Conclusion;
                            }
                            break;
                        case "10":  //HL
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.HL = Convert.ToDecimal(result.TestValue);
                                model.HLJudge = result.Conclusion;
                            }
                            break;
                        case "12":  //Sieve35
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Sieve35 = Convert.ToDecimal(result.TestValue);
                                model.Sieve35Judge = result.Conclusion;
                            }
                            break;
                        case "13":  //Sieve100
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Sieve100 = Convert.ToDecimal(result.TestValue);
                                model.Sieve100Judge = result.Conclusion;
                            }
                            break;
                        case "14":  //筛渣#325
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Sieve325 = Convert.ToDecimal(result.TestValue);
                                model.Sieve325Judge = result.Conclusion;
                            }
                            break;
                        case "15":  //LT
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.LT = Convert.ToDecimal(result.TestValue);
                                model.LTJudge = result.Conclusion;
                            }
                            break;
                        case "16":  //PD
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PD = Convert.ToDecimal(result.TestValue);
                                model.PDJudge = result.Conclusion;
                            }
                            break;
                        case "17":  //PH
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PH = Convert.ToDecimal(result.TestValue);
                                model.PHJudge = result.Conclusion;
                            }
                            break;
                        case "19":  //PSD10
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD10 = Convert.ToDecimal(result.TestValue);
                                model.PSD10Judge = result.Conclusion;
                            }
                            break;
                        case "20":  //PSD18
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD18 = Convert.ToDecimal(result.TestValue);
                                model.PSD18Judge = result.Conclusion;
                            }
                            break;
                        case "21":  //PSD35
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD35 = Convert.ToDecimal(result.TestValue);
                                model.PSD35Judge = result.Conclusion;
                            }
                            break;
                        case "22":  //PSD60
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD60 = Convert.ToDecimal(result.TestValue);
                                model.PSD60Judge = result.Conclusion;
                            }
                            break;
                        case "23":  //PSD120
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD120 = Convert.ToDecimal(result.TestValue);
                                model.PSD120Judge = result.Conclusion;
                            }
                            break;
                        case "24":  //PSDpan
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSDpan = Convert.ToDecimal(result.TestValue);
                                model.PSDpanJudge = result.Conclusion;
                            }
                            break;
                        case "25":  //Tint
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Tint = Convert.ToDecimal(result.TestValue);
                                model.TintJudge = result.Conclusion;
                            }
                            break;
                        case "26":  //CDBP
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.CDBP = Convert.ToDecimal(result.TestValue);
                                model.CDBPJudge = result.Conclusion;
                            }
                            break;
                        case "28":  //N2SA
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.N2SA = Convert.ToDecimal(result.TestValue);
                                model.N2SAJudge = result.Conclusion;
                            }
                            break;
                        case "35":  //STSA
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.STSA = Convert.ToDecimal(result.TestValue);
                                model.STSAJudge = result.Conclusion;
                            }
                            break;
                        case "27":  //Ash
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Ash = Convert.ToDecimal(result.TestValue);
                                model.AshJudge = result.Conclusion;
                            }
                            break;
                            //////////////////////////////////////////////华丽的分割线

 
        //public decimal? MH { get; set; }
        //public string MHJudge { get; set; }


        //public decimal? T10 { get; set; }
        //public string T10Judge { get; set; }


        //public decimal? T50 { get; set; }
        //public string T50Judge { get; set; }


        //public decimal? T90 { get; set; }
        //public string T90Judge { get; set; }

        //public decimal? MV { get; set; }
        //public string MVJudge { get; set; }

        //public decimal? MST { get; set; }
        //public string MSTJudge { get; set; }

        //public decimal? HUB { get; set; }
        //public string HUBJudge { get; set; }

        //public decimal? Rebound { get; set; }
        //public string ReboundJudge { get; set; }

        //public decimal? EB { get; set; }
        //public string EBJudge { get; set; }

        //public decimal? Modulus300 { get; set; }
        //public string Modulus300Judge { get; set; }


        //public decimal? TB { get; set; }
        //public string TBJudge { get; set; }

                        case "65":  //ML
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.ML = Convert.ToDecimal(result.TestValue);
                                model.MLJudge = result.Conclusion;
                            }
                            break;

                        case "41":  //MH
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.MH = Convert.ToDecimal(result.TestValue);
                                model.MHJudge = result.Conclusion;
                            }
                            break;
                        case "39":  //  T10
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.T10 = Convert.ToDecimal(result.TestValue);
                                model.T10Judge = result.Conclusion;
                            }
                            break;
                        case "43":  // T50
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.T50 = Convert.ToDecimal(result.TestValue);
                                model.T50Judge = result.Conclusion;
                            }
                            break;
                        case "40":  //  T90
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.T90 = Convert.ToDecimal(result.TestValue);
                                model.T90Judge = result.Conclusion;
                            }
                            break;

                        case "36":  // MV
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.MV = Convert.ToDecimal(result.TestValue);
                                model.MVJudge = result.Conclusion;
                            }
                            break;

                        case "42":  // MST
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.MST = Convert.ToDecimal(result.TestValue);
                                model.MSTJudge = result.Conclusion;
                            }
                            break;

                        case "44":  // HBU
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.HBU = Convert.ToDecimal(result.TestValue);
                                model.HBUJudge = result.Conclusion;
                            }
                            break;
                        case "34":  // Rebound
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Rebound = Convert.ToDecimal(result.TestValue);
                                model.ReboundJudge = result.Conclusion;
                            }
                            break;
                        case "33":  // EB
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.EB = Convert.ToDecimal(result.TestValue);
                                model.EBJudge = result.Conclusion;
                            }
                            break;
                        case "31":  // Modulus300
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Modulus300 = Convert.ToDecimal(result.TestValue);
                                model.Modulus300Judge = result.Conclusion;
                            }
                            break;
                        case "32":  // Modulus300
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.TB = Convert.ToDecimal(result.TestValue);
                                model.TBJudge = result.Conclusion;
                            }
                            break;
                    }
                }
                listForGrid.Add(model);
            }
            return listForGrid;
        }

        /// <summary>
        /// 转换成品报告的查询结果用来绑定到grid
        /// </summary>
        /// <param name="reportList"></param>
        /// <returns></returns>
        public static List<ReportMixModel> TransformMixReport(PagedList<ReportMix> reportList)
        {
            List<ReportMixModel> listForGrid = new List<ReportMixModel>();
            foreach (var report in reportList)
            {

                ReportMixModel model = new ReportMixModel();
                model.ReportMixID = report.ReportMixID;
                model.GoodsID = report.GoodsID;
                model.GoodsName = report.Good.GoodsName;
                model.SamplingPlaceMixID = report.SamplingPlaceMixID;
                model.SamplingPlaceName = report.SamplingPlaceMix.SamplingPlaceName;
                model.ProduceDate = report.ProduceDate;
                model.SendDate = report.SendDate;
                model.LotNO = report.LotNO;
                model.SampleSendPerson = report.SampleSendPerson;
                model.Factory = report.Factory;
                model.SampleNO = report.SampleNO;
                model.Conclusion = report.Conclusion;
                model.TestDate = report.TestDate;
                model.PackingQuantity = report.PackingQuantity;
                model.packingSpecification = report.packingSpecification;
                model.BagQuantity = report.BagQuantity;
                model.SampleQuantity = report.SampleQuantity;
                model.Environment = report.Environment;
                model.ReportNO = report.ReportNO;

                model.LoginUserID = report.LoginUserID;
                model.AddDateTime = report.AddDateTime;
                model.ReportMixResults = report.ReportMixResults.ToList();

                foreach (var result in report.ReportMixResults)
                {
                    string id = result.TestItemID;
                    switch (id)
                    {
                        case "1": //IA
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.IA = Convert.ToDecimal(result.TestValue);
                                model.IAJudge = result.Conclusion;
                            }
                            break;
                        case "7":   //DBP
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.DBP = Convert.ToDecimal(result.TestValue);
                                model.DBPJudge = result.Conclusion;
                            }
                            break;
                        case "46":  //IPH(AVG)
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.IPH_AVG = Convert.ToDecimal(result.TestValue);
                                model.IPH_AVGJudge = result.Conclusion;
                            }
                            break;
                        case "8":  //IPH(IPH_High)
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.IPH_High = Convert.ToDecimal(result.TestValue);
                                model.IPH_HighJudge = result.Conclusion;
                            }
                            break;
                        case "30":  //IPH_Low
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.IPH_Low = Convert.ToDecimal(result.TestValue);
                                model.IPH_LowJudge = result.Conclusion;
                            }
                            break;
                        case "9":  //Fines
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Fines = Convert.ToDecimal(result.TestValue);
                                model.FinesJudge = result.Conclusion;
                            }
                            break;
                        case "10":  //HL
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.HL = Convert.ToDecimal(result.TestValue);
                                model.HLJudge = result.Conclusion;
                            }
                            break;
                        case "12":  //Sieve35
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Sieve35 = Convert.ToDecimal(result.TestValue);
                                model.Sieve35Judge = result.Conclusion;
                            }
                            break;
                        case "13":  //Sieve100
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Sieve100 = Convert.ToDecimal(result.TestValue);
                                model.Sieve100Judge = result.Conclusion;
                            }
                            break;
                        case "14":  //筛渣#325
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Sieve325 = Convert.ToDecimal(result.TestValue);
                                model.Sieve325Judge = result.Conclusion;
                            }
                            break;
                        case "15":  //LT
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.LT = Convert.ToDecimal(result.TestValue);
                                model.LTJudge = result.Conclusion;
                            }
                            break;
                        case "16":  //PD
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PD = Convert.ToDecimal(result.TestValue);
                                model.PDJudge = result.Conclusion;
                            }
                            break;
                        case "17":  //PH
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PH = Convert.ToDecimal(result.TestValue);
                                model.PHJudge = result.Conclusion;
                            }
                            break;
                        case "19":  //PSD10
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD10 = Convert.ToDecimal(result.TestValue);
                                model.PSD10Judge = result.Conclusion;
                            }
                            break;
                        case "20":  //PSD18
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD18 = Convert.ToDecimal(result.TestValue);
                                model.PSD18Judge = result.Conclusion;
                            }
                            break;
                        case "21":  //PSD35
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD35 = Convert.ToDecimal(result.TestValue);
                                model.PSD35Judge = result.Conclusion;
                            }
                            break;
                        case "22":  //PSD60
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD60 = Convert.ToDecimal(result.TestValue);
                                model.PSD60Judge = result.Conclusion;
                            }
                            break;
                        case "23":  //PSD120
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD120 = Convert.ToDecimal(result.TestValue);
                                model.PSD120Judge = result.Conclusion;
                            }
                            break;
                        case "24":  //PSDpan
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSDpan = Convert.ToDecimal(result.TestValue);
                                model.PSDpanJudge = result.Conclusion;
                            }
                            break;
                        case "25":  //Tint
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Tint = Convert.ToDecimal(result.TestValue);
                                model.TintJudge = result.Conclusion;
                            }
                            break;
                        case "26":  //CDBP
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.CDBP = Convert.ToDecimal(result.TestValue);
                                model.CDBPJudge = result.Conclusion;
                            }
                            break;
                        case "28":  //N2SA
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.N2SA = Convert.ToDecimal(result.TestValue);
                                model.N2SAJudge = result.Conclusion;
                            }
                            break;
                        case "35":  //STSA
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.STSA = Convert.ToDecimal(result.TestValue);
                                model.STSAJudge = result.Conclusion;
                            }
                            break;


                        case "27":  //Ash
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Ash = Convert.ToDecimal(result.TestValue);
                                model.AshJudge = result.Conclusion;
                            }
                            break;
                    }
                }
                listForGrid.Add(model);
            }

            return listForGrid;
        }


        public static List<ReportProductModel> TransformProductReport(PagedList<ReportProduct> reportList)
        {
            List<ReportProductModel> listForGrid = new List<ReportProductModel>();
            foreach (var report in reportList)
            {
                ReportProductModel model = new ReportProductModel();
                model.AddDateTime = report.AddDateTime;
                model.CustomerID = report.CustomerID;
                model.DateProduced = report.DateProduced;
                model.ExPlant = report.ExPlant;
                model.GoodsID = report.GoodsID;
                model.LoginUserID = report.LoginUserID;
                model.LotNo = report.LotNo;
                model.Remark = report.Remark;
                model.ReportProductID = report.ReportProductID;
                model.ReportProductNO = report.ReportProductNO;
                model.ReportProductResults = report.ReportProductResults.ToList();
                model.ShippedTo = report.ShippedTo;
                model.TypeOfPack = report.TypeOfPack;
                model.Weight = report.Weight;

                foreach (var result in report.ReportProductResults)
                {
                    string id = result.TestItemID;
                    #region MyRegion
                  
                    switch (id)
                    {
                        case "1": //IA
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.IA = Convert.ToDecimal(result.TestValue);
                                model.IAJudge = result.Conclusion;
                            }
                            break;
                        case "7":   //DBP
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.DBP = Convert.ToDecimal(result.TestValue);
                                model.DBPJudge = result.Conclusion;
                            }
                            break;
                        case "46":  //IPH(AVG)
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.IPH_AVG = Convert.ToDecimal(result.TestValue);
                                model.IPH_AVGJudge = result.Conclusion;
                            }
                            break;
                        case "8":  //IPH(IPH_High)
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.IPH_High = Convert.ToDecimal(result.TestValue);
                                model.IPH_HighJudge = result.Conclusion;
                            }
                            break;
                        case "30":  //IPH_Low
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.IPH_Low = Convert.ToDecimal(result.TestValue);
                                model.IPH_LowJudge = result.Conclusion;
                            }
                            break;
                        case "9":  //Fines
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Fines = Convert.ToDecimal(result.TestValue);
                                model.FinesJudge = result.Conclusion;
                            }
                            break;
                        case "10":  //HL
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.HL = Convert.ToDecimal(result.TestValue);
                                model.HLJudge = result.Conclusion;
                            }
                            break;
                        case "12":  //Sieve35
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Sieve35 = Convert.ToDecimal(result.TestValue);
                                model.Sieve35Judge = result.Conclusion;
                            }
                            break;
                        case "13":  //Sieve100
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Sieve100 = Convert.ToDecimal(result.TestValue);
                                model.Sieve100Judge = result.Conclusion;
                            }
                            break;
                        case "14":  //筛渣#325
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Sieve325 = Convert.ToDecimal(result.TestValue);
                                model.Sieve325Judge = result.Conclusion;
                            }
                            break;
                        case "15":  //LT
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.LT = Convert.ToDecimal(result.TestValue);
                                model.LTJudge = result.Conclusion;
                            }
                            break;
                        case "16":  //PD
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PD = Convert.ToDecimal(result.TestValue);
                                model.PDJudge = result.Conclusion;
                            }
                            break;
                        case "17":  //PH
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PH = Convert.ToDecimal(result.TestValue);
                                model.PHJudge = result.Conclusion;
                            }
                            break;
                        case "19":  //PSD10
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD10 = Convert.ToDecimal(result.TestValue);
                                model.PSD10Judge = result.Conclusion;
                            }
                            break;
                        case "20":  //PSD18
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD18 = Convert.ToDecimal(result.TestValue);
                                model.PSD18Judge = result.Conclusion;
                            }
                            break;
                        case "21":  //PSD35
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD35 = Convert.ToDecimal(result.TestValue);
                                model.PSD35Judge = result.Conclusion;
                            }
                            break;
                        case "22":  //PSD60
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD60 = Convert.ToDecimal(result.TestValue);
                                model.PSD60Judge = result.Conclusion;
                            }
                            break;
                        case "23":  //PSD120
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSD120 = Convert.ToDecimal(result.TestValue);
                                model.PSD120Judge = result.Conclusion;
                            }
                            break;
                        case "24":  //PSDpan
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.PSDpan = Convert.ToDecimal(result.TestValue);
                                model.PSDpanJudge = result.Conclusion;
                            }
                            break;
                        case "25":  //Tint
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Tint = Convert.ToDecimal(result.TestValue);
                                model.TintJudge = result.Conclusion;
                            }
                            break;
                        case "26":  //CDBP
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.CDBP = Convert.ToDecimal(result.TestValue);
                                model.CDBPJudge = result.Conclusion;
                            }
                            break;
                        case "28":  //N2SA
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.N2SA = Convert.ToDecimal(result.TestValue);
                                model.N2SAJudge = result.Conclusion;
                            }
                            break;

                        case "35":  //STSA
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.STSA = Convert.ToDecimal(result.TestValue);
                                model.STSAJudge = result.Conclusion;
                            }
                            break;

                        case "27":  //Ash
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Ash = Convert.ToDecimal(result.TestValue);
                                model.AshJudge = result.Conclusion;
                            }
                            break;
                            //////////////////////////////////////////////////////////////////////////////
                        case "36":  //mv  
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.MV = Convert.ToDecimal(result.TestValue);
                                model.MVJudge = result.Conclusion;
                            }
                            break;


                        case "42":  //MST_T5
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.MST_T5 = Convert.ToDecimal(result.TestValue);
                                model.MST_T5Judge = result.Conclusion;
                            }
                            break;
                        case "39":  //T10
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.T10 = Convert.ToDecimal(result.TestValue);
                                model.T10Judge = result.Conclusion;
                            }
                            break;

                        case "43":  //T50
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.T50 = Convert.ToDecimal(result.TestValue);
                                model.T50Judge = result.Conclusion;
                            }
                            break;

                        case "40":  //T90
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.T90 = Convert.ToDecimal(result.TestValue);
                                model.T90Judge = result.Conclusion;
                            }
                            break;

                        case "41":  //MH
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.MH = Convert.ToDecimal(result.TestValue);
                                model.MHJudge = result.Conclusion;
                            }
                            break;

                        case "62":  //Hardness
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Hardness = Convert.ToDecimal(result.TestValue);
                                model.HardnessJudge = result.Conclusion;
                            }
                            break;

                        case "31":  //300% Modulus
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Modulus300 = Convert.ToDecimal(result.TestValue);
                                model.Modulus300Judge = result.Conclusion;
                            }
                            break;

                        case "33":  //EB
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.EB = Convert.ToDecimal(result.TestValue);
                                model.EBJudge = result.Conclusion;
                            }
                            break;

                        case "32":  //TB
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Ash = Convert.ToDecimal(result.TestValue);
                                model.AshJudge = result.Conclusion;
                            }
                            break;
                        case "34":  //Rebound
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Rebound = Convert.ToDecimal(result.TestValue);
                                model.ReboundJudge = result.Conclusion;
                            }
                            break;

                        case "44":  //HBU
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.HBU = Convert.ToDecimal(result.TestValue);
                                model.HBUJudge = result.Conclusion;
                            }
                            break;

                        case "45":  //Lambourn
                            if (!String.IsNullOrEmpty(result.TestValue))
                            {
                                model.Lambourn = Convert.ToDecimal(result.TestValue);
                                model.LambournJudge = result.Conclusion;
                            }
                            break;
                    }

                    #endregion
                }
                listForGrid.Add(model);
            }
            return listForGrid;
        }


        #region 废弃代码
        //public static DataTable Test(IQueryable<ReportSemi> reportList)
        //{
        //    DataSet1 set = new DataSet1();
        //    DataTable tableMain = set.Tables["ReportSemiTable"];
        //    foreach (var report in reportList)
        //    {
        //        DataRow dr = tableMain.NewRow();
        //        dr["ReportSemiID"] = report.ReportSemiID;
        //        dr["GoodsID"] = report.GoodsID;
        //        dr["GoodsName"] = report.Good.GoodsName;
        //        dr["SamplingPlaceID"] = report.SamplingPlaceID;
        //        dr["SamplingPlaceName"] = report.SamplingPlace.SamplingPlaceName;
        //        dr["ProductionLineID"] = report.ProductionLineID;
        //        dr["ProductionGroupID"] = report.ProductionGroupID;
        //        dr["SendDate"] = report.SendDate;
        //        dr["Remark"] = report.Remark;
        //        dr["LoginUserID"] = report.LoginUserID;
        //        dr["AddDateTime"] = report.AddDateTime;
        //        tableMain.Rows.Add(dr);

        //        foreach (var result in report.ReportSemiResults)
        //        {
        //            string id = result.TestItemID;
        //            switch (id)
        //            {
        //                case "1": //IA
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["IA"] = Convert.ToDecimal(result.TestValue);
        //                        dr["IAJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "7":   //DBP
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["DBP"] = Convert.ToDecimal(result.TestValue);
        //                        dr["DBPJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "46":  //IPH(AVG)
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["IPH_AVG"] = Convert.ToDecimal(result.TestValue);
        //                        dr["IPH_AVGJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "8":  //IPH(IPH_High)
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["IPH_High"] = Convert.ToDecimal(result.TestValue);
        //                        dr["IPH_HighJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "30":  //IPH_Low
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["IPH_Low"] = Convert.ToDecimal(result.TestValue);
        //                        dr["IPH_LowJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "9":  //Fines
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["Fines"] = Convert.ToDecimal(result.TestValue);
        //                        dr["FinesJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "10":  //HL
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["HL"] = Convert.ToDecimal(result.TestValue);
        //                        dr["HLJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "12":  //Sieve35
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["Sieve35"] = Convert.ToDecimal(result.TestValue);
        //                        dr["Sieve35Judge"] = result.Conclusion;

        //                    }
        //                    break;
        //                case "13":  //Sieve100
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["Sieve100"] = Convert.ToDecimal(result.TestValue);
        //                        dr["Sieve100Judge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "14":  //筛渣#325
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["Sieve325"] = Convert.ToDecimal(result.TestValue);
        //                        dr["Sieve325Judge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "15":  //LT
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["LT"] = Convert.ToDecimal(result.TestValue);
        //                        dr["LTJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "16":  //PD
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["PD"] = Convert.ToDecimal(result.TestValue);
        //                        dr["PDJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "17":  //PH
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["PH"] = Convert.ToDecimal(result.TestValue);
        //                        dr["PHJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "19":  //PSD10
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["PSD10"] = Convert.ToDecimal(result.TestValue);
        //                        dr["PSD10Judge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "20":  //PSD18
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["PSD18"] = Convert.ToDecimal(result.TestValue);
        //                        dr["PSD18Judge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "21":  //PSD35
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["PSD35"] = Convert.ToDecimal(result.TestValue);
        //                        dr["PSD35Judge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "22":  //PSD60
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["PSD60"] = Convert.ToDecimal(result.TestValue);
        //                        dr["PSD60Judge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "23":  //PSD120
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["PSD120"] = Convert.ToDecimal(result.TestValue);
        //                        dr["PSD120Judge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "24":  //PSDpan
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["PSDpan"] = Convert.ToDecimal(result.TestValue);
        //                        dr["PSDpanJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "25":  //Tint
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["Tint"] = Convert.ToDecimal(result.TestValue);
        //                        dr["TintJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "26":  //CDBP
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["CDBP"] = Convert.ToDecimal(result.TestValue);
        //                        dr["CDBPJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "28":  //N2SA
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["N2SA"] = Convert.ToDecimal(result.TestValue);
        //                        dr["N2SAJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //                case "27":  //Ash
        //                    if (!String.IsNullOrEmpty(result.TestValue))
        //                    {
        //                        dr["Ash"] = Convert.ToDecimal(result.TestValue);
        //                        dr["AshJudge"] = result.Conclusion;
        //                    }
        //                    break;
        //            }
        //        }

        //    }
        //    return tableMain;
        //}
        #endregion
       





//        select a.ReportSemiID,
//a.GoodsID,
//a.Remark,
//a.ProductionLineID,
//case when b.TestItemID='1' then TestValue end 项目1,
//case when b.TestItemID='7' then TestValue end 项目2,
//case when b.TestItemID='8' then TestValue end 项目3,
//case when b.TestItemID='9' then TestValue end 项目4,
//case when b.TestItemID='10' then TestValue end 项目5,
//case when b.TestItemID='13' then TestValue end 项目6,
//case when b.TestItemID='14' then TestValue end 项目7
//from ReportSemis a left join ReportSemiResults b on a.ReportSemiID=b.ReportSemiID

    }
}
